package cn.k.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

@Getter
@Setter
public class Notice {
    public static final int READ_TYPE_FALSE=0; //未读
    public static final int READ_TYPE_TRUE=1; //已读

    public static final int LEVEL_TYPE_URGENT=1;  //紧急
    public static final int LEVEL_TYPE_IMPORTANT=2; //重要
    public static final int LEVEL_TYPE_ORDINARY=3; //普通

    public static final int SAVE_TYPE_STATUS=0; //未发布
    public static final int SAVE_TYPE_STATUS1=1; //已发布

    /** 编号*/
    private Long id;
    /** 公告标题*/
    private String title;
    /** 创建人*/
    private String name;
    /** 创建时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    /** 公告级别*/
    private Integer level=LEVEL_TYPE_ORDINARY;
    /** 是否已读*/
    private Integer readId=READ_TYPE_FALSE;
    /** 发布状态*/
    private int releaseStatus;
    /** 公告内容*/
    private String content;

    private Long employeeId; //用户id
    private int status; //已读状态


    public String getLevelDisplay(){
        switch (level){
            case LEVEL_TYPE_URGENT :return "紧急";
            case LEVEL_TYPE_IMPORTANT :return "重要";
            case LEVEL_TYPE_ORDINARY :return "普通";
            default: return "未知";
        }
    }



    public String getReadIdDisplay(){
        switch (status){
            case READ_TYPE_FALSE :return "未读";
            case READ_TYPE_TRUE :return "已读";
            default: return "未知";
        }
    }

    public String getReleaseStatusDisplay(){
        if (releaseStatus==0){
            return "未发布";
        }else if (releaseStatus==1){
            return "发布";
        }
        else {
            return "未知";
        }

    }


    public String toJson(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("name",name);
        map.put("level",level);
        map.put("content",content);
        //map.put("createTime",createTime);
        return JSON.toJSONString(map);
    }


}